from selenium import webdriver
import pytest
from Test_baidu_web.Page.Page import Page
@pytest.fixture(scope='function')
def get_driver():
    driver = webdriver.Chrome()
    driver.implicitly_wait(3)
    yield driver
    driver.close()
def test_01(get_driver):
    driver = get_driver
    page = Page(driver)
    page.url_open()
    title = page.title()
    print(title)
    # 断言页面标题，验证是否打开百度网站
    try:
        assert title == '百度一下，你就知道'
    except Exception as e:
        print(e)
def test_02(get_driver):
    driver = get_driver
    page = Page(driver)
    page.url_open()
    title = page.title()
    print(title)
    page.send_test_search()
    page.click_search_button()
    result = page.get_address1()
    print(result)
    # 断言 ,验证返回的搜索结果是否包含搜索目标
    try:
        assert '软件测试' in result
    except Exception as e:
        print(e)
def test_03(get_driver):
    driver = get_driver
    page = Page(driver)
    page.url_open()
    title = page.title()
    print(title)
    page.send_test_search()
    page.click_search_button()

    result = page.get_address1()
    print(result)
    result_2 = page.get_address2()
    result_3 = page.get_address3()
    result_4  = page.get_address4()
    print(result_2)
    print(result_3)
    print(result_4)
    try:
        assert '软甲测试' in result
        assert '软件测试' in result_2
        assert '软件测试' in result_3
        assert '软件测试' in result_4
    except Exception as e:
        print(e)
def test_04(get_driver):
    driver = get_driver
    page = Page(driver)
    page.url_open()
    title = page.title()
    print(title)
    page.send_test_search()
    page.click_search_button()
    # 获取页面返回的文本
    result = page.get_address1()
    result_2 = page.get_address2()
    result_3 = page.get_address3()
    result_4  = page.get_address4()
    print(result)
    print(result_2)
    print(result_3)
    print(result_4)
    # 断言
    # 通过获取的网站标题文本，判断是否返回需要的搜索结果
    try:
        assert '软甲测试' in result
        assert '软件测试' in result_2
        assert '软件测试' in result_3
        assert '软件测试' in result_4
    except Exception as e:
        print(e)
def test_05(get_driver):
    driver = get_driver
    page = Page(driver)
    page.url_open()
    title = page.title()
    print(title)
    page.send_test_search()
    page.click_search_button()
    page.scroll()
    page.click_change_page()
    # 获取网站的标题
    result = page.get_address6()
    result_2 = page.get_address7()
    result_3 = page.get_address8()
    result_4 = page.get_address9()
    print(result)
    print(result_2)
    print(result_3)
    print(result_4)
    # 断言
    # 通过获取的网站标题文本，判断是否返回需要的搜索结果
    try:
        assert '软甲测试' in result
        assert '软件测试' in result_2
        assert '软件测试' in result_3
        assert '软件测试' in result_4
        print('')
    except Exception as e:
        print('没有找到对应文本')

































